package haemers.reflection.tests 
{
	import nl.haemers.data.constants.DataTypes;
	import nl.haemers.data.reflection.Type;
	import nl.haemers.data.reflection.Variable;
	import org.flexunit.Assert;
	/**
	 * ...
	 * @author Jonathan
	 */
	public class VariableTest 
	{
		private var _intVariable:Variable;
		private var _arrayVariable:Variable;
		private var _customObjectVariable:Variable;
		
		/** Public methods **/
		[Before]
		public function setup() : void
		{
			_intVariable = new Variable(_intXML);
			_arrayVariable = new Variable(_arrayXML);
			_customObjectVariable = new Variable(_customObjectXML);
		}
		
		[Test]
		public function testBasicVariable():void
		{
			Assert.assertFalse(_intVariable.hasSerialize());
			Assert.assertFalse(_intVariable.ignore);
			Assert.assertNotNull(_intVariable.metadatas);
			Assert.assertEquals("id", _intVariable.name);
			Assert.assertNull(_intVariable.objectType);
			Assert.assertFalse(_intVariable.overwriteable);
			Assert.assertEquals("id", _intVariable.propertyName);
			Assert.assertEquals("id", _intVariable.toString(), _intVariable.name);
			Assert.assertTrue(_intVariable.writeable);
		}
		
		[Test]
		public function testArrayVariable() : void
		{
			Assert.assertNotNull(_arrayVariable.objectType);
			Assert.assertTrue(_arrayVariable.objectType is Type);
		}
		
		[Test]
		public function testCustomObject() : void
		{
			Assert.assertNotNull(_customObjectVariable.objectType);
			Assert.assertTrue(_customObjectVariable.objectType is Type);
		}
		
		[Test]
		public function testIgnoreVariable() : void
		{
			Assert.assertTrue(_arrayVariable.ignore);
		}
		
		[Test]
		public function testSerializeVariable() : void
		{
			Assert.assertEquals("child", _customObjectVariable.name);
			Assert.assertEquals("nested", _customObjectVariable.propertyName);
			
			//TODO: Look for a method to compare 2 values these can't be equal!
		}
		
		[Test]
		public function testDataTypes() : void
		{
			Assert.assertEquals(DataTypes.INT, _intVariable.dataType);
			Assert.assertEquals(DataTypes.ARRAY, _arrayVariable.dataType);
		}
		
		[After]
		public function teardown() : void
		{
			_intVariable = null;
			_arrayVariable = null;
			_customObjectVariable = null;
		}
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
		private var _intXML:XML = new XML(
			<variable name="id" type="int">
				<metadata name="__go_to_definition_help">
				  <arg key="pos" value="127"/>
				</metadata>
			</variable>
		);
		
		private var _arrayXML:XML = new XML(
			<variable name="collection" type="Array">
				<metadata name="Serialize">
				  <arg key="ignore" value="true"/>
				</metadata>
				<metadata name="__go_to_definition_help">
				  <arg key="pos" value="276"/>
				</metadata>
			</variable>
		);
		
		private var _customObjectXML:XML = new XML(
			<variable name="nested" type="haemers.reflection.data.vo::VariableVO">
				<metadata name="Serialize">
				  <arg key="name" value="child"/>
				</metadata>
				<metadata name="__go_to_definition_help">
				  <arg key="pos" value="209"/>
				</metadata>
			</variable>
		);
	}
}